<template>
  <ContentWrap>
    <Workcompent :value="xmlString" @init-finished="initModeler" v-bind="controlForm" />
  </ContentWrap>
</template>

<script setup lang="ts" name="work">
import Workcompent from './Workcompent.vue'
import * as ModelApi from '@/api/bpm/model'
const { query } = useRoute()
const message = useMessage() // 国际化
const xmlString = ref(undefined) // BPMN XML
const modeler = ref(null) // BPMN Modeler
const model = ref<ModelApi.ModelVO>() // 流程模型的信息
const controlForm = ref({
  prefix: 'flowable'
})

/** 初始化 modeler */
const initModeler = (item) => {
  setTimeout(() => {
    modeler.value = item
  }, 10)
}
onMounted(async () => {
  const modelId = query.modelId as unknown as number
  if (!modelId) {
    message.error('缺少模型modelId编号')
    return
  }
  // 查询模型
  const data = await ModelApi.getModel(modelId)
  xmlString.value = data.bpmnXml
  model.value = {
    ...data,
    bpmnXml: undefined // 清空 bpmnXml 属性
  }
  console.log(xmlString, model, modeler)
})
</script>

<style lang="scss" scoped></style>
